{-# LANGUAGE DeriveDataTypeable         #-}
{-# OPTIONS -Wall #-}

--------------------------------------------------------------------------------
-- |
-- Module      :  Lambola.IDL.Syntax
-- Copyright   :  (c) Stephen Tetley 2014
-- License     :  BSD3
--
-- Maintainer  :  stephen.tetley@gmail.com
-- Stability   :  unstable
-- Portability :  GHC
--
-- Parser.
-- 
--------------------------------------------------------------------------------

module Lambola.IDL.Syntax
 
  where

import Data.Data

type Identifier = String

data Definition = TypedefDcl    TypeSpec [Declarator]
                | TypeDcl       TypeSpec 
                | AttrDcl       AccessSpec TypeSpec [Declarator]
                | ForwardDcl    Identifier
                | InterfaceDcl  Identifier [ScopedName] [Definition]
                | ConstDcl      TypeSpec Identifier ConstExp
                | Module        Identifier [Definition]
                | ExceptDcl     Identifier [Member]
                | OpDcl         OpAttribute TypeSpec Identifier 
                                [ParamDcl] (Maybe RaisesExpr) (Maybe ContextExpr)
  deriving (Eq,Show,Data,Typeable)


data ParamDcl =  ParamDcl ParamAttribute TypeSpec Declarator
  deriving (Eq,Show,Data,Typeable)



data AccessSpec = READONLY | ACCESS_RW
  deriving (Enum,Eq,Ord,Show,Data,Typeable)


data OpAttribute = ONEWAY | NO_ATTR
  deriving (Enum,Eq,Ord,Show,Data,Typeable)



data Member = Member TypeSpec [Declarator]
  deriving (Eq,Show,Data,Typeable)

data TypeSpec = TyNamed ScopedName
              | TyVoid
              | TyBoolean
              | TyInt IntSpecifier
              | TyFloat FloatSpecifier
              | TyChar
              | TyString (Maybe ConstExp)    -- possibly length bound
              | TyOctet
              | TyAny
              | TyStruct Identifier [Member]
              | TyUnion Identifier TypeSpec [UnionCase]
              | TyEnum Identifier [Identifier]
              | TySequence TypeSpec (Maybe ConstExp)
  deriving (Eq,Show,Data,Typeable)

data IntSpecifier = SIGNED_LONG_INT
                  | SIGNED_SHORT_INT
                  | UNSIGNED_LONG_INT
                  | UNSIGNED_SHORT_INT
  deriving (Enum,Eq,Ord,Show,Data,Typeable)

data FloatSpecifier = FLOAT
                    | DOUBLE
  deriving (Enum,Eq,Ord,Show,Data,Typeable)

data UnionCase = UnionCase [CaseLabel] ElementSpec
  deriving (Eq,Show,Data,Typeable)


data CaseLabel = CaseOf ConstExp
               | CaseDefault
  deriving (Eq,Show,Data,Typeable)

data ElementSpec = ElementSpec TypeSpec Declarator
  deriving (Eq,Show,Data,Typeable)


data ConstExp = UnaryExp      UnaryOp ConstExp  
              | BinaryExp     BinaryOp ConstExp ConstExp
              | NamedExp      ScopedName
              | IntegerLit    Integer
              | StringLit     String
              | CharLit       Char
              | FloatingPtLit Double
              | BooleanLit    Bool
  deriving (Eq,Show,Data,Typeable)


data BinaryOp = BIN_OR | BIN_XOR | BIN_AND | BIN_SHIFTR | BIN_SHIFTL
              | BIN_PLUS | BIN_MINUS | BIN_MULT | BIN_DIV | BIN_MOD
  deriving (Enum,Eq,Ord,Show,Data,Typeable)

data UnaryOp = UNARY_NEGATE | UNARY_PLUS | UNARY_BNOT
  deriving (Enum,Eq,Ord,Show,Data,Typeable)

data Declarator = SimpleDeclarator Identifier
                | ArrayDeclarator Identifier [ConstExp]
  deriving (Eq,Show,Data,Typeable)


data ParamAttribute = IN | OUT | INOUT
  deriving (Enum,Eq,Ord,Show,Data,Typeable)

data ScopedName = ScopedName [Identifier] Identifier
  deriving (Eq,Show,Data,Typeable)


type RaisesExpr = [ScopedName]

type ContextExpr = [String]